
$.extend(planner, {
        contact: {
                ui: {
                        init: function(){
                                $("#messagesent").hide();
                                $("#messagefail").hide();
                        },
                        setup: function(){
                                $('#submitmessage').button().click(function(){
                                        $("#messagesent").hide();
                                        $("#messagefail").hide();
                                
                                        $.ajax({ 
                                                url: "/m",
                                                dataType: 'json',
                                                type: "POST",
                                                data: {
                                                        name: $("#messagename").val(),
                                                        mail: $("#messagemail").val(),
                                                        text: $("#messagetext").val(),
                                                }
                                        }).done(function(data){
                                                planner.contact.ui.display_error(data);
                                        }).fail(function(){
                                                planner.contact.ui.display_error();
                                        });
                                    
                                        return false;
                                });
                        },
                        display_error: function(code)
                        {
                                id = ""
                                
                                if (code == "0") {
                                        id = "#messagesent"
                                } else if (code=="4") {
                                        $("#messagefail").text("DB-Error.")
                                        id = "#messagefail"
                                } else if (code=="3") {
                                        $("#messagefail").text("Mail-Provider error.")
                                        id = "#messagefail"
                                } else if (code == "2") {
                                        $("#messagefail").text("Please write a message.")
                                        id = "#messagefail"
                                } else if (code == "1") {
                                        $("#messagefail").text("Please specify a name.")
                                        id = "#messagefail"
                                } else {
                                        $("#messagefail").text("Most likely a server problem.")
                                        id = "#messagefail"
                                }
                        
                                setTimeout( function(){ $(id).hide(duration=300) }, 100 );
                                setTimeout( function(){ $(id).show(duration=300) }, 5000 );
                        }
                }
        }
});